require('es6-promise').polyfill();

import axios from 'axios'

function loadBills(data) {
  return {
    type: 'LOAD_BILL_MANAGER_DATA',
    data
  }
}

export function apiMsgAction(msg) {
  return {
    type: 'API_MSG',
    msg
  }
}

export function loadBillAsync(data) {
  if (typeof data.search_is_pay != 'undefined' && data.search_is_pay != null) {
    data.is_pay = data.search_is_pay
  }
  return function(dispatch) {
    return axios.post('/api/bill/queryBillManager', data).then(
      resp => dispatch(loadBills(resp.data)),
      error => dispatch(apiMsgAction(error.data.errMsg))
    )
  }
}

export function exportBillAsync(data) {
  if (typeof data.search_is_pay != 'undefined' && data.search_is_pay != null) {
    data.is_pay = data.search_is_pay
  }
  return function(dispatch) {
    return axios.post('/api/bill/export', data).then(function(resp) {

    })
    .catch(function(err) {
      dispatch(apiMsgAction(error.data.errMsg))
    })
  };
}
